<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *留言记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'留言列表'),
);
if($_RQ['op']=='list'){
	$type=intval($_RQ['type']);
	$params=array('uniacid'=>$_SESSION['uniacid'],'checked'=>0,'gamename'=>$this->plugin_name);
	if($type){
		$params['type']=$type;
		$return['params']['type']=$type;
	}
	if(!empty($_RQ['pid'])){
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=intval($_RQ['pid']);
	}
	if(!empty($_RQ['ptile'])){
		$pid=pdo_getcolumn('jy_merch_game_item_msg',array('uniacid'=>$_SESSION['uniacid'],'title like %'=>$_RQ['ptile'].'%'),'id');
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=$_RQ['pid'];
	}
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_merch_game_item_msg',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		$item['ptitle']=pdo_getcolumn('jy_merch_game_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']),'title');
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'pid','title'=>'主题ID','type'=>'string'),
			array('name'=>'ptitle','title'=>'主题名称','type'=>'string'),
			array('name'=>'mid','title'=>'用户ID','type'=>'string'),
			array('name'=>'member','title'=>'用户信息_Member','type'=>'member'),
			array('name'=>'title','title'=>'留言语句','type'=>'string'),
			array('name'=>'checked','title'=>'审核状态','type'=>'switch','set'=>'checked'),
			array('name'=>'createtime','title'=>'留言时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'pid','width'=>15,'title'=>'主题ID','type'=>'string'),
			array('name'=>'ptile','width'=>15,'title'=>'主题名称','type'=>'string'),
			array('name'=>'nickname','width'=>15,'title'=>'留言人昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='checked'){
	if($_RQ['id']){
		$id=intval($_RQ['id']);
	}
	$post=get_postdata();
	pdo_update('jy_merch_game_item_msg',array('checked'=>intval($post['checked'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('设置成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_merch_game_item_msg',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
